package com.sky.controller.user;
import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.UserShopCarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author 符健清
 * @version 1.0
 * 用户购物车 控制器
 */
@SuppressWarnings({"all"})
@Slf4j
@Api(tags = "购物车接口")
@RestController
@RequestMapping("/user/shoppingCart")
public class UserShopCarController {
    @Autowired
    private UserShopCarService userShopCarService;
    /**
     * 添加购物车
     */
    @ApiOperation("添加购物车")
    @PostMapping("/add")
    public Result  addShoppingCart (@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("ShoppingCartDTO:{}",shoppingCartDTO);
        userShopCarService.insertShoppingCar(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 查询购物车
     */
    @ApiOperation(" 查看 购物车")
    @GetMapping("/list")
    public Result< List <ShoppingCart>> selectShppingCart() {
        List<ShoppingCart> list =userShopCarService.selectShppingCart();
        Result<ShoppingCart> result = new Result<>();
       return  result.success(list);
    }
    /**
     * 清空购物车
     */
    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
     public Result cleanShoppingCart () {
         userShopCarService.cleanShoppingCarts ();
         return  Result.success();
     }
    /**
     * 删除购物车的数量 减一
     */
    @ApiOperation("数量减 1")
    @PostMapping("/sub")
    public Result  deleteShoppingCart (@RequestBody ShoppingCartDTO shoppingCartDTO){
        userShopCarService.deleteShoppingCart(shoppingCartDTO);
        return Result.success();
    }

}
